﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using dhDataAcess.orderLinqDAL;
using dhDataAcess.Model;
using dhDataAcess.linqDAL;

namespace dhDataAcess.orderDAL
{
   public class orderDetailDAL
    {
           string  tableName = "orderDetail";
        private SqlTransaction tran = null;
        private SqlConnection conn = null;
        public orderDetailDAL(SqlTransaction _transaction, SqlConnection _conn)
        {
            tran = _transaction ;
            conn = _conn;
        }
        /// <summary>
        /// 插入产品信息表数据
        /// </summary>
        /// <param name="deptRow"></param>
        /// <returns></returns>
        public int orderDetailInsert(orderDetailModel row)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            string insertstr = baseBLL.dTableColumnRead.insertSqlStr(tableName).ToString();
            SqlParameter[] para = {
                                      new SqlParameter ("@waifa",row .waifa  ),
                                        new SqlParameter ("@mark",row .mark ),
                                        new SqlParameter ("@updateUser",row .updateUser ),
                                        new SqlParameter ("@updateDate",row .updateDate ),
                                        new SqlParameter ("@ptype",row .ptype ),
                                        new SqlParameter ("@detailStatus",row .detailStatus ),
                                        new SqlParameter ("@proType",row .proType ),
                                        new SqlParameter ("@account",row .account ),
                                        new SqlParameter ("@price",row .price ),
                                        new SqlParameter ("@qty",row .qty ),
                                        new SqlParameter ("@unit",row .unit ),
                                        new SqlParameter ("@colorNum",row .colorNum ),
                                        new SqlParameter ("@pcolor",row .pcolor ),
                                        new SqlParameter ("@pname",row .pname ),
                                        new SqlParameter ("@orderDetailNo",row .orderDetailNo ),
                                        new SqlParameter ("@orderNo",row .orderNo ),
                                        new SqlParameter ("@stockQty","0" ),
                                         new SqlParameter ("@hetongNo",row .hetongNo ),
                                          new SqlParameter ("@blStatus",row .blStatus  ),
                                          new SqlParameter ("@waifacust",row .waifacust   )
                                    };
            cmd.Parameters.AddRange(para);
            cmd.CommandText = insertstr;
            cmd.Transaction = tran;
            int i = cmd.ExecuteNonQuery();
            return i;
        }
        /// <summary>
        /// 更新产品信息表数据
        /// </summary>
        /// <param name="deptRow"></param>
        /// <returns></returns>
        public int orderDetailUpdate(orderDetailModel row)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            string updatestr = "update orderDetail set mark=@mark,updateUser=@updateUser,updateDate=@updateDate,ptype=@ptype,detailStatus=@detailStatus,proType=@proType,account=@account,price=@price,qty=@qty,unit=@unit,colorNum=@colorNum,pcolor=@pcolor,pname=@pname,orderDetailNo=@orderDetailNo,orderNo=@orderNo,hetongNo=@hetongNo,waifa=@waifa,blStatus=@blStatus,waifacust=@waifacust where orderDetailNo=@orderDetailNo";
         // string updatestr = baseBLL.dTableColumnRead.updateSqlStr(tableName).ToString();
          SqlParameter[] para = {
                                     new SqlParameter ("@waifa",row .waifa  ),
                                        new SqlParameter ("@mark",row .mark ),
                                        new SqlParameter ("@updateUser",row .updateUser ),
                                        new SqlParameter ("@updateDate",row .updateDate ),
                                        new SqlParameter ("@ptype",row .ptype ),
                                        new SqlParameter ("@detailStatus",row .detailStatus ),
                                        new SqlParameter ("@proType",row .proType ),
                                        new SqlParameter ("@account",row .account ),
                                        new SqlParameter ("@price",row .price ),
                                        new SqlParameter ("@qty",row .qty ),
                                        new SqlParameter ("@unit",row .unit ),
                                        new SqlParameter ("@colorNum",row .colorNum ),
                                        new SqlParameter ("@pcolor",row .pcolor ),
                                        new SqlParameter ("@pname",row .pname ),
                                        new SqlParameter ("@orderDetailNo",row .orderDetailNo ),
                                        new SqlParameter ("@orderNo",row .orderNo ),
                                         new SqlParameter ("@hetongNo",row .hetongNo ),
                                         new SqlParameter ("@blStatus",row .blStatus  ),
                                         new SqlParameter ("@waifacust",row .waifacust   )
                                    };
            cmd.Parameters.AddRange(para);
            cmd.CommandText = updatestr;
            cmd.Transaction = tran;
            int i = cmd.ExecuteNonQuery();
            return i;
        }
        /// <summary>
        /// 删除一行产品信息表数据
        /// </summary>
        /// <param name="deptRow"></param>
        /// <returns></returns>
        public int orderDetailDel(string orderDetailNo)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            string deletestr = baseBLL.dTableColumnRead.delSqlStr (tableName).ToString();
            SqlParameter[] para = {
                                
                                    new SqlParameter ("@orderDetailNo",orderDetailNo)
                                  }; 
            cmd.Parameters.AddRange(para);
            cmd.CommandText = deletestr ;
            cmd.Transaction = tran;
            int i = cmd.ExecuteNonQuery();
            return i;
        }
    }
}
